cmake_minimum_required(VERSION 3.1.3)
project(speech-server)
set(CMAKE_CXX_STANDARD 17)

set(src_path "${CMAKE_CURRENT_SOURCE_DIR}/source")
file(GLOB src_files "${src_path}/*.cc")
file(GLOB test_client_file "${CMAKE_CURRENT_SOURCE_DIR}/test/*.cc")
set(proto_path "${CMAKE_CURRENT_SOURCE_DIR}/../proto")
set(proto_file_name "speech.proto")
set(CMAKE_BUILD_TYPE "Debug")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -O0 -ggdb")
message("${proto_path}/${proto_file_name}")
string(REPLACE ".proto" ".pb.cc" proto_cc ${proto_file_name})
message("proto_cc的值 : ${proto_cc}")
message("proto_path的值 : ${proto_path}")


if(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/proto_cc)
    message("进入生成proto文件判断")
    message("生成的proto_cc文件路径: ${CMAKE_CURRENT_BINARY_DIR}/${proto_cc}")
    add_custom_command(
        PRE_BUILD
        COMMAND protoc
        ARGS --cpp_out=${CMAKE_CURRENT_BINARY_DIR} --proto_path=${proto_path} ${proto_path}/${proto_file_name}
        DEPENDS "${proto_path}/${proto_file_name}"
        OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${proto_cc}"
        COMMENT "生成proto框架代码文件: ${proto_cc}"
        COMMENT "--cpp_out=${CMAKE_CURRENT_BINARY_DIR} --proto_path=${proto_path} ${proto_path}/${proto_file_name}"
    )
endif()

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../common)
message("构建speech的目录: ${CMAKE_CURRENT_BINARY_DIR}")
include_directories(${CMAKE_CURRENT_BINARY_DIR})


list(APPEND proto_ccs "${CMAKE_CURRENT_BINARY_DIR}/${proto_cc}")
message("proto_ccs的值 : ${proto_ccs}")
add_executable(speech_server ${src_files} ${proto_ccs})
add_executable(test_client ${test_client_file} ${proto_ccs})

target_link_libraries(speech_server brpc leveldb gflags ssl curl crypto protobuf etcd-cpp-api cpprest fmt jsoncpp spdlog fmt)
target_link_libraries(test_client brpc leveldb gflags ssl curl crypto protobuf etcd-cpp-api cpprest fmt jsoncpp spdlog fmt)

install(TARGETS speech_server RUNTIME DESTINATION bin)